import warnings
warnings.filterwarnings('ignore')
## Get data
from dataframes import final_df_dict
from sympy import *
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
from ipywidgets import Output
from tqdm import tqdm
df = final_df_dict['decision'].copy()
print(df.shape)
df.dropna(inplace=True)
print(df.shape)
df430_pre = df[(df['participant.inflation'] == '430') & (df['participant.day'] < 3)]
df1012_pre = df[(df['participant.inflation'] == '1012') & (df['participant.day'] < 3)]
df430_post = df[(df['participant.inflation'] == '430') & (df['participant.day'] >= 3)]
df1012_post = df[(df['participant.inflation'] == '1012') & (df['participant.day'] >= 3)]
print(df430_pre.shape, df1012_pre.shape, df430_post.shape, df1012_post.shape)
dfs = {'430_pre': df430_pre,
'1012_pre': df1012_pre,
'430_post': df430_post,
'1012_post': df1012_post}
## Calculate average value for each month
quantity_430_pre = np.array([])
quantity_1012_pre = np.array([])
quantity_430_post = np.array([])
quantity_1012_post = np.array([])
quantities = {}
for k, v in dfs.items():
quantities[k] = np.array([])
print(quantities)
for n in range(1,121):
quantities[k] = np.append(quantities[k], v[f'task.{n}.player.decision'].mean())
# quantity_430_pre = np.append(quantity_430_pre, df430_pre[f'task.{n}.player.decision'].mean())
# quantity_1012_pre = np.append(quantity_1012_pre, df1012_pre[f'task.{n}.player.decision'].mean())
# quantity_430_post = np.append(quantity_430_post, df430_post[f'task.{n}.player.decision'].mean())
# quantity_1012_post = np.append(quantity_1012_post, df1012_post[f'task.{n}.player.decision'].mean())
# qs = [quantity_430_pre,quantity_1012_pre,quantity_430_post,quantity_1012_post,]
# for i in range(len(qs)):
# for n in range(1,121):
# qs[i] = np.append(qs[i], dfs[i][f'task.{n}.player.decision'].mean())
# print('quantity', len(quantity_430_pre), type(quantity_430_pre))
months = np.array([n for n in range(1,121)])
for k, v in quantities.items():
print(len(v), len(months))
plt.errorbar(months, v, 0.3, fmt='o', label=k)
plt.legend(
loc="upper right",
)
# label=[
# '430_pre',
# '1012_pre',
# '430_post',
# '1012_post',
(442, 126)
(442, 126)
(117, 126) (115, 126) (105, 126) (105, 126)
{'430_pre': array([], dtype=float64)}
{'430_pre': array([23.8974359 , 3.2991453 , 2.76923077, 3.70940171, 2.93162393,
2.48717949, 2.02564103, 1.94871795, 1.93162393, 2.11111111,
2.11111111, 2.15384615, 2.1025641 , 1.08547009, 0.91452991,
1.90598291, 0.79487179, 1.1965812 , 1.16239316, 1.22222222,
1.20512821, 1.1025641 , 1.26495726, 1.53846154, 2.37606838,
1.74358974, 0.52136752, 1.06837607, 0.5982906 , 1.06837607,
2.92307692, 2.65811966, 1.35897436, 0.87179487, 0.97435897,
0.92307692, 2.08547009, 1.17094017, 1.95726496, 0.99145299,
0.76923077, 0.82905983, 0.68376068, 0.52136752, 0.35042735,
1.4957265 , 0.54700855, 0.90598291, 0.96581197, 0.94017094,
0.85470085, 0.25641026, 1.26495726, 0.33333333, 0.32478632,
0.28205128, 0.86324786, 0.2991453 , 0.24786325, 0.53846154,
1.07692308, 0.27350427, 0.26495726, 0.41025641, 0.2991453 ,
0.41025641, 0.33333333, 0.38461538, 0.47863248, 0.21367521,
0.30769231, 0.58119658, 0.63247863, 0.41025641, 0.25641026,
0.16239316, 0.17948718, 0.34188034, 0.20512821, 0.24786325,
0.30769231, 0.32478632, 0.30769231, 0.5042735 , 0.2991453 ,
0.4957265 , 0.18803419, 0.16239316, 0.21367521, 0.26495726,
0.4017094 , 0.41025641, 0.45299145, 0.15384615, 0.11965812,
0.35042735, 0.24786325, 0.30769231, 0.28205128, 0.11965812,
0.26495726, 0.14529915, 0.41880342, 0.12820513, 0.09401709,
0.20512821, 0.08547009, 0.2991453 , 0.41025641, 0.31623932,
0.12820513, 0.1025641 , 0.11111111, 0.12820513, 0.09401709,
0.14529915, 0.08547009, 0.13675214, 0.14529915, 0.37606838]), '1012_pre': array([], dtype=float64)}
{'430_pre': array([23.8974359 , 3.2991453 , 2.76923077, 3.70940171, 2.93162393,
2.48717949, 2.02564103, 1.94871795, 1.93162393, 2.11111111,
2.11111111, 2.15384615, 2.1025641 , 1.08547009, 0.91452991,
1.90598291, 0.79487179, 1.1965812 , 1.16239316, 1.22222222,
1.20512821, 1.1025641 , 1.26495726, 1.53846154, 2.37606838,
1.74358974, 0.52136752, 1.06837607, 0.5982906 , 1.06837607,
2.92307692, 2.65811966, 1.35897436, 0.87179487, 0.97435897,
0.92307692, 2.08547009, 1.17094017, 1.95726496, 0.99145299,
0.76923077, 0.82905983, 0.68376068, 0.52136752, 0.35042735,
1.4957265 , 0.54700855, 0.90598291, 0.96581197, 0.94017094,
0.85470085, 0.25641026, 1.26495726, 0.33333333, 0.32478632,
0.28205128, 0.86324786, 0.2991453 , 0.24786325, 0.53846154,
1.07692308, 0.27350427, 0.26495726, 0.41025641, 0.2991453 ,
0.41025641, 0.33333333, 0.38461538, 0.47863248, 0.21367521,
0.30769231, 0.58119658, 0.63247863, 0.41025641, 0.25641026,
0.16239316, 0.17948718, 0.34188034, 0.20512821, 0.24786325,
0.30769231, 0.32478632, 0.30769231, 0.5042735 , 0.2991453 ,
0.4957265 , 0.18803419, 0.16239316, 0.21367521, 0.26495726,
0.4017094 , 0.41025641, 0.45299145, 0.15384615, 0.11965812,
0.35042735, 0.24786325, 0.30769231, 0.28205128, 0.11965812,
0.26495726, 0.14529915, 0.41880342, 0.12820513, 0.09401709,
0.20512821, 0.08547009, 0.2991453 , 0.41025641, 0.31623932,
0.12820513, 0.1025641 , 0.11111111, 0.12820513, 0.09401709,
0.14529915, 0.08547009, 0.13675214, 0.14529915, 0.37606838]), '1012_pre': array([20.62608696, 5.13913043, 2.2173913 , 3.96521739, 2.67826087,
2.72173913, 2.56521739, 1.70434783, 1.71304348, 1.57391304,
3.31304348, 1.7826087 , 4.26086957, 2.4173913 , 2.69565217,
1.20869565, 0.86956522, 1.35652174, 1.25217391, 0.86956522,
0.91304348, 1.09565217, 0.90434783, 1.30434783, 1.32173913,
1.40869565, 1.00869565, 0.9826087 , 0.63478261, 0.63478261,
0.8 , 1.08695652, 0.70434783, 0.54782609, 0.67826087,
0.76521739, 2.51304348, 1.7826087 , 1.0173913 , 1.28695652,
0.29565217, 0.33913043, 0.39130435, 0.4 , 0.26086957,
0.73913043, 0.77391304, 1.07826087, 0.88695652, 0.76521739,
0.71304348, 0.49565217, 0.47826087, 0.74782609, 0.50434783,
0.53913043, 0.88695652, 0.39130435, 0.53913043, 0.43478261,
0.73043478, 0.53043478, 0.4 , 0.24347826, 0.65217391,
0.51304348, 0.43478261, 0.24347826, 0.46086957, 0.33913043,
0.27826087, 0.43478261, 0.55652174, 0.7826087 , 0.69565217,
0.24347826, 0.6173913 , 0.37391304, 0.55652174, 0.29565217,
0.28695652, 0.55652174, 0.45217391, 0.24347826, 0.84347826,
0.20869565, 0.49565217, 0.2173913 , 0.14782609, 0.1826087 ,
0.17391304, 0.42608696, 0.20869565, 0.11304348, 0.25217391,
0.28695652, 0.54782609, 0.31304348, 0.37391304, 0.40869565,
0.43478261, 0.28695652, 0.19130435, 0.27826087, 0.19130435,
0.27826087, 0.4173913 , 0.36521739, 0.22608696, 0.4 ,
0.15652174, 0.3826087 , 0.14782609, 0.2 , 0.13043478,
0.26086957, 0.14782609, 0.13913043, 0.16521739, 0.44347826]), '430_post': array([], dtype=float64)}
{'430_pre': array([23.8974359 , 3.2991453 , 2.76923077, 3.70940171, 2.93162393,
2.48717949, 2.02564103, 1.94871795, 1.93162393, 2.11111111,
2.11111111, 2.15384615, 2.1025641 , 1.08547009, 0.91452991,
1.90598291, 0.79487179, 1.1965812 , 1.16239316, 1.22222222,
1.20512821, 1.1025641 , 1.26495726, 1.53846154, 2.37606838,
1.74358974, 0.52136752, 1.06837607, 0.5982906 , 1.06837607,
2.92307692, 2.65811966, 1.35897436, 0.87179487, 0.97435897,
0.92307692, 2.08547009, 1.17094017, 1.95726496, 0.99145299,
0.76923077, 0.82905983, 0.68376068, 0.52136752, 0.35042735,
1.4957265 , 0.54700855, 0.90598291, 0.96581197, 0.94017094,
0.85470085, 0.25641026, 1.26495726, 0.33333333, 0.32478632,
0.28205128, 0.86324786, 0.2991453 , 0.24786325, 0.53846154,
1.07692308, 0.27350427, 0.26495726, 0.41025641, 0.2991453 ,
0.41025641, 0.33333333, 0.38461538, 0.47863248, 0.21367521,
0.30769231, 0.58119658, 0.63247863, 0.41025641, 0.25641026,
0.16239316, 0.17948718, 0.34188034, 0.20512821, 0.24786325,
0.30769231, 0.32478632, 0.30769231, 0.5042735 , 0.2991453 ,
0.4957265 , 0.18803419, 0.16239316, 0.21367521, 0.26495726,
0.4017094 , 0.41025641, 0.45299145, 0.15384615, 0.11965812,
0.35042735, 0.24786325, 0.30769231, 0.28205128, 0.11965812,
0.26495726, 0.14529915, 0.41880342, 0.12820513, 0.09401709,
0.20512821, 0.08547009, 0.2991453 , 0.41025641, 0.31623932,
0.12820513, 0.1025641 , 0.11111111, 0.12820513, 0.09401709,
0.14529915, 0.08547009, 0.13675214, 0.14529915, 0.37606838]), '1012_pre': array([20.62608696, 5.13913043, 2.2173913 , 3.96521739, 2.67826087,
2.72173913, 2.56521739, 1.70434783, 1.71304348, 1.57391304,
3.31304348, 1.7826087 , 4.26086957, 2.4173913 , 2.69565217,
1.20869565, 0.86956522, 1.35652174, 1.25217391, 0.86956522,
0.91304348, 1.09565217, 0.90434783, 1.30434783, 1.32173913,
1.40869565, 1.00869565, 0.9826087 , 0.63478261, 0.63478261,
0.8 , 1.08695652, 0.70434783, 0.54782609, 0.67826087,
0.76521739, 2.51304348, 1.7826087 , 1.0173913 , 1.28695652,
0.29565217, 0.33913043, 0.39130435, 0.4 , 0.26086957,
0.73913043, 0.77391304, 1.07826087, 0.88695652, 0.76521739,
0.71304348, 0.49565217, 0.47826087, 0.74782609, 0.50434783,
0.53913043, 0.88695652, 0.39130435, 0.53913043, 0.43478261,
0.73043478, 0.53043478, 0.4 , 0.24347826, 0.65217391,
0.51304348, 0.43478261, 0.24347826, 0.46086957, 0.33913043,
0.27826087, 0.43478261, 0.55652174, 0.7826087 , 0.69565217,
0.24347826, 0.6173913 , 0.37391304, 0.55652174, 0.29565217,
0.28695652, 0.55652174, 0.45217391, 0.24347826, 0.84347826,
0.20869565, 0.49565217, 0.2173913 , 0.14782609, 0.1826087 ,
0.17391304, 0.42608696, 0.20869565, 0.11304348, 0.25217391,
0.28695652, 0.54782609, 0.31304348, 0.37391304, 0.40869565,
0.43478261, 0.28695652, 0.19130435, 0.27826087, 0.19130435,
0.27826087, 0.4173913 , 0.36521739, 0.22608696, 0.4 ,
0.15652174, 0.3826087 , 0.14782609, 0.2 , 0.13043478,
0.26086957, 0.14782609, 0.13913043, 0.16521739, 0.44347826]), '430_post': array([31.54285714, 3.8 , 2.7047619 , 2.60952381, 1.72380952,
1.18095238, 2.08571429, 1.6952381 , 1.62857143, 1.43809524,
3.0952381 , 1.72380952, 2.14285714, 1.05714286, 1.0952381 ,
1.20952381, 0.76190476, 1.14285714, 1.96190476, 1.5047619 ,
0.73333333, 0.73333333, 1.32380952, 2.80952381, 2.51428571,
1.25714286, 0.99047619, 1. , 1.0952381 , 1.27619048,
6.76190476, 3.02857143, 0.48571429, 0.76190476, 1.24761905,
0.78095238, 1.54285714, 1.46666667, 0.72380952, 0.51428571,
0.51428571, 0.6952381 , 0.39047619, 1.01904762, 0.71428571,
0.60952381, 0.48571429, 0.64761905, 0.99047619, 0.76190476,
0.59047619, 0.40952381, 0.39047619, 0.31428571, 0.46666667,
0.36190476, 0.45714286, 0.2 , 0.22857143, 0.26666667,
0.46666667, 0.3047619 , 0.35238095, 0.43809524, 0.36190476,
0.44761905, 0.34285714, 0.53333333, 0.45714286, 0.54285714,
0.21904762, 0.98095238, 0.35238095, 0.20952381, 0.22857143,
0.21904762, 0.22857143, 0.41904762, 0.22857143, 0.31428571,
0.26666667, 0.22857143, 0.22857143, 0.44761905, 0.21904762,
0.4 , 0.20952381, 0.20952381, 0.20952381, 0.19047619,
0.76190476, 0.17142857, 0.13333333, 0.3047619 , 0.17142857,
0.20952381, 0.33333333, 0.48571429, 0.22857143, 0.26666667,
0.07619048, 0.07619048, 0.15238095, 0.22857143, 0.18095238,
0.08571429, 0.11428571, 0.0952381 , 0.31428571, 0.20952381,
0.15238095, 0.14285714, 0.06666667, 0.05714286, 0.11428571,
0.05714286, 0.07619048, 0.06666667, 0.08571429, 0.16190476]), '1012_post': array([], dtype=float64)}
120 120
120 120
120 120
120 120
<matplotlib.legend.Legend at 0x2421d914e80>
df = final_df_dict['decision'].copy()
print(df.shape)
df.dropna(inplace=True)
print(df.shape)
cols430 = ['task.29.player.decision','task.30.player.decision','task.31.player.decision','task.32.player.decision',
'task.59.player.decision','task.60.player.decision','task.61.player.decision','task.62.player.decision',
'task.89.player.decision','task.90.player.decision','task.91.player.decision','task.92.player.decision',]
cols1012 = ['task.11.player.decision','task.12.player.decision','task.13.player.decision','task.14.player.decision',
'task.35.player.decision','task.36.player.decision','task.37.player.decision','task.38.player.decision',
'task.59.player.decision','task.60.player.decision','task.61.player.decision','task.62.player.decision',
'task.83.player.decision','task.84.player.decision','task.85.player.decision','task.86.player.decision',
'task.107.player.decision','task.108.player.decision','task.109.player.decision','task.110.player.decision',]
df430_pre = df[cols430][(df['participant.inflation'] == '430') & (df['participant.day'] < 3)]
df1012_pre = df[cols1012][(df['participant.inflation'] == '1012') & (df['participant.day'] < 3)]
df430_post = df[cols430][(df['participant.inflation'] == '430') & (df['participant.day'] >= 3)]
df1012_post = df[cols1012][(df['participant.inflation'] == '1012') & (df['participant.day'] >= 3)]
print(df430_pre.shape, df1012_pre.shape, df430_post.shape, df1012_post.shape)
dfs = {'430_pre': df430_pre,
'1012_pre': df1012_pre,
'430_post': df430_post,
'1012_post': df1012_post}
# for k, v in dfs.items():
# plt.hist(v)
# plt.hist(df430_pre, df430_post)
# df430_post
plt.hist([df430_pre[cols430[1+1]],df430_post[cols430[1+1]],df430_pre[cols430[2+1]],
df430_post[cols430[2+1]]], alpha=0.5, label=['430_pre 31','430_post 31',
'430_pre 32','430_post 32'])
# plt.bar_label([df430_pre,df430_post], fontsize=20, color='navy')
# plt.hist(df430_post, alpha=0.5, label='430_post')
plt.legend(loc='upper right')
plt.show()
plt.hist([df430_pre[cols430[5+1]],df430_post[cols430[5+1]],df430_pre[cols430[6+1]],
df430_post[cols430[6+1]]], alpha=0.5, label=['430_pre 61','430_post 61',
'430_pre 62','430_post 62'])
# plt.bar_label([df430_pre,df430_post], fontsize=20, color='navy')
# plt.hist(df430_post, alpha=0.5, label='430_post')
plt.legend(loc='upper right')
plt.show()
plt.hist([df430_pre[cols430[10]],df430_post[cols430[10]],df430_pre[cols430[11]],
df430_post[cols430[11]]], alpha=0.5, label=['430_pre 91','430_post 91',
'430_pre 92','430_post 92'])
# plt.bar_label([df430_pre,df430_post], fontsize=20, color='navy')
# plt.hist(df430_post, alpha=0.5, label='430_post')
plt.legend(loc='upper right')
plt.show()
plt.hist([df1012_pre[cols1012[1]],df1012_post[cols1012[1]],df1012_pre[cols1012[2]],
df1012_post[cols1012[2]]], alpha=0.5, label=['1012_pre 12','1012_post 12',
'1012_pre 13','1012_post 13'])
plt.legend(loc='upper right')
plt.show()
(442, 126) (442, 126) (117, 12) (115, 20) (105, 12) (105, 20)
est = final_df_dict['inf_estimate'].copy()
inf_1012 = [0.45, 60.79, 0.45, 60.79, 0.45, 60.79, 0.45, 60.79, 0.45, 60.79]
inf_430 = [0.38, 0.47, 26.85, 55.49, 64.18, 0.38, 0.47, 26.85, 55.49, 64.18]
rev_1012 = [x[1] - x[0] for x in zip(inf_1012, inf_1012[1:])]
rev_430 = [x[1] - x[0] for x in zip(inf_430, inf_430[1:])]
for n in range(2,11):
est[f'{12 * n}-{12 * (n - 1)}'] = est[f'task.{n * 12}.player.inf_estimate'] -\
est[f'task.{(n - 1) * 12}.player.inf_estimate']
est['revisions'] = np.nan
for i in range(len(est)):
x = 0
for n in range(2,11):
if est[f'{12 * n}-{12 * (n - 1)}'].iloc[i] != 0:
x += 1
else:
pass
est['revisions'].iloc[i] = x
## Graph estimates
cols = [c for c in est.columns.to_list() if ('task.' in c)]
fig, ax = plt.subplots(figsize=(24, 10))
## Actual inflation
## 10x12 pre
df = est[cols][
(est['participant.inflation'] == '1012') & (est['participant.day'] < 3) & (
est['revisions'] >= 0
)
].T
df_cols = ['_' + str(col) for col in df.columns]
df_cols[0] = '10x12 pre'
df.columns = df_cols
df.plot(ax=ax, color='r', alpha=0.1)
# ax.get_legend().remove()
## 10x12 post
df = est[cols][
(est['participant.inflation'] == '1012') & (est['participant.day'] >= 3) & (
est['revisions'] >= 0
)
].T
df_cols = ['_' + str(col) for col in df.columns]
df_cols[0] = '10x12 post'
df.columns = df_cols
df.plot(ax=ax, color='b', alpha=0.1)
# ax.get_legend().remove()
plt.axhline(y=60.79, color='g', linestyle=':', label='max inflation')
plt.axhline(y=0, color='black', linestyle='-')
plt.plot(inf_1012, color='#f2f542', linewidth=4, label='actual inflation')
plt.legend(loc = 'upper left')
plt.title('10x12 perceptions')
fig, ax = plt.subplots(figsize=(24, 10))
## 4x30 pre
df = est[cols][
(est['participant.inflation'] == '430') & (est['participant.day'] < 3) & (
est['revisions'] >= 0
)
].T
df_cols = ['_' + str(col) for col in df.columns]
df_cols[0] = '4x30 pre'
df.columns = df_cols
df.plot(ax=ax, color='r', alpha=0.1)
# ax.get_legend().remove()
## 4x30 post
df = est[cols][
(est['participant.inflation'] == '430') & (est['participant.day'] >= 3) & (
est['revisions'] >= 0
)
].T
df_cols = ['_' + str(col) for col in df.columns]
df_cols[0] = '4x30 post'
df.columns = df_cols
df.plot(ax=ax, color='b', alpha=0.1)
# ax.get_legend().remove()
plt.axhline(y=64.18, color='g', linestyle=':', label='max inflation')
plt.axhline(y=0, color='black', linestyle='-')
plt.plot(inf_430, color='#f2f542', linewidth=4, label='actual inflation')
plt.legend(loc = 'upper left')
plt.title('4x30 perceptions')
## Graph revisions
cols = [c for c in est.columns.to_list() if ('-' in c)]
fig, ax = plt.subplots(figsize=(24, 10))
## 10x12 pre
df = est[cols][
(est['participant.inflation'] == '1012') & (est['participant.day'] < 3) & (
est['revisions'] >= 0
)
].T
df_cols = ['_' + str(col) for col in df.columns]
df_cols[0] = '10x12 pre'
df.columns = df_cols
df.plot(ax=ax, color='r', alpha=0.1)
# ax.get_legend().remove()
## 10x12 post
df = est[cols][
(est['participant.inflation'] == '1012') & (est['participant.day'] >= 3) & (
est['revisions'] >= 0
)
].T
df_cols = ['_' + str(col) for col in df.columns]
df_cols[0] = '10x12 post'
df.columns = df_cols
df.plot(ax=ax, color='b', alpha=0.1)
# ax.get_legend().remove()
plt.axhline(y=60.79, color='g', linestyle=':', label='max inflation')
plt.axhline(y=0, color='black', linestyle='-')
plt.plot(rev_1012, color='#f2f542', linewidth=4, label='correct revision')
plt.legend(loc = 'upper left')
plt.title('10x12 revisions')
fig, ax = plt.subplots(figsize=(24, 10))
## 4x30 pre
df = est[cols][
(est['participant.inflation'] == '430') & (est['participant.day'] < 3) & (
est['revisions'] >= 0
)
].T
df_cols = ['_' + str(col) for col in df.columns]
df_cols[0] = '4x30 pre'
df.columns = df_cols
df.plot(ax=ax, color='r', alpha=0.1)
# ax.get_legend().remove()
## 4x30 post
df = est[cols][
(est['participant.inflation'] == '430') & (est['participant.day'] >= 3) & (
est['revisions'] >= 0
)
].T
df_cols = ['_' + str(col) for col in df.columns]
df_cols[0] = '4x30 post'
df.columns = df_cols
df.plot(ax=ax, color='b', alpha=0.1)
# ax.get_legend().remove()
plt.axhline(y=64.18, color='g', linestyle=':', label='max inflation')
plt.axhline(y=0, color='black', linestyle='-')
plt.plot(rev_430, color='#f2f542', linewidth=4, label='correct revision')
plt.legend(loc = 'upper left')
plt.title('4x30 revisions')
Text(0.5, 1.0, '4x30 revisions')
cols = est.columns.to_list()
print(cols)
['participant.code', 'participant.label', 'participant.time_started_utc', 'participant.inflation', 'participant.intervention', 'participant.day', 'task.12.player.inf_estimate', 'task.24.player.inf_estimate', 'task.36.player.inf_estimate', 'task.48.player.inf_estimate', 'task.60.player.inf_estimate', 'task.72.player.inf_estimate', 'task.84.player.inf_estimate', 'task.96.player.inf_estimate', 'task.108.player.inf_estimate', 'task.120.player.inf_estimate', '24-12', '36-24', '48-36', '60-48', '72-60', '84-72', '96-84', '108-96', '120-108', 'revisions']
def fft_row_magnitudes(row):
fft = np.fft.fft(row)
magnitudes = np.abs(fft)
# power_spectrum = np.abs(fft)**2
est['estimate'] = ''
## Create columns for lists of estimates
for i in range(len(est)):
estimate = est.iloc[i].to_list()
estimate = estimate[6:15]
# ## Convert stock values to int
# stock = [int(i) for i in stock]
est['estimate'].iloc[i] = estimate
est['fft_magnitudes'] = ''
for i in range(len(est)):
fft = np.fft.fft(est['estimate'].iloc[i])
est['fft_magnitudes'].iloc[i] = np.abs(fft)
# power_spectrum = np.abs(fft)**2
# est['fft_magnitudes'] = est['estimate'].apply(fft_row_magnitudes)
## Frequencies of each curve
N = len(est['fft_magnitudes'].iloc[1]) # length of the magnitude list
sampling_rate = 1 # assuming a sampling rate of 1
frequencies = [(i / N) * sampling_rate for i in range(N)]
periodicities = [1 / i for i in frequencies if i != 0]
print(frequencies, len(frequencies))
print(periodicities, len(frequencies))
N = len(est['fft_magnitudes'].iloc[2]) # length of the magnitude list
sampling_rate = 1 # assuming a sampling rate of 1
frequencies = [(i / N) * sampling_rate for i in range(N)]
periodicities = [1 / i for i in frequencies if i != 0]
print(frequencies, len(frequencies))
print(periodicities, len(frequencies))
[0.0, 0.1111111111111111, 0.2222222222222222, 0.3333333333333333, 0.4444444444444444, 0.5555555555555556, 0.6666666666666666, 0.7777777777777778, 0.8888888888888888] 9 [9.0, 4.5, 3.0, 2.25, 1.7999999999999998, 1.5, 1.2857142857142856, 1.125] 9 [0.0, 0.1111111111111111, 0.2222222222222222, 0.3333333333333333, 0.4444444444444444, 0.5555555555555556, 0.6666666666666666, 0.7777777777777778, 0.8888888888888888] 9 [9.0, 4.5, 3.0, 2.25, 1.7999999999999998, 1.5, 1.2857142857142856, 1.125] 9
cols = [c for c in est.columns.to_list() if ('task.' in c)]
fig, ax = plt.subplots(figsize=(20,20))
df1 = est[cols][(est['participant.inflation'] == '430') & (
est['participant.day'] < 3
)]
df1.hist(ax=ax, color='r', label='pre')
fig, ax = plt.subplots(figsize=(20,20))
# ax = fig.gca()
df2 = est[cols][(est['participant.inflation'] == '430') & (
est['participant.day'] >= 3
)]
df2.hist(ax=ax, color='b', label='post')
# ax.legend(loc='upper right')
# plt.show()
fig, ax = plt.subplots(figsize=(20,20))
df1 = est[cols][(est['participant.inflation'] == '1012') & (
est['participant.day'] < 3
)]
df1.hist(ax=ax, color='r', label='pre')
fig, ax = plt.subplots(figsize=(20,20))
# ax = fig.gca()
df2 = est[cols][(est['participant.inflation'] == '1012') & (
est['participant.day'] >= 3
)]
df2.hist(ax=ax, color='b', label='post')
array([[<AxesSubplot:title={'center':'task.12.player.inf_estimate'}>,
<AxesSubplot:title={'center':'task.24.player.inf_estimate'}>,
<AxesSubplot:title={'center':'task.36.player.inf_estimate'}>],
[<AxesSubplot:title={'center':'task.48.player.inf_estimate'}>,
<AxesSubplot:title={'center':'task.60.player.inf_estimate'}>,
<AxesSubplot:title={'center':'task.72.player.inf_estimate'}>],
[<AxesSubplot:title={'center':'task.84.player.inf_estimate'}>,
<AxesSubplot:title={'center':'task.96.player.inf_estimate'}>,
<AxesSubplot:title={'center':'task.108.player.inf_estimate'}>],
[<AxesSubplot:title={'center':'task.120.player.inf_estimate'}>,
<AxesSubplot:>, <AxesSubplot:>]], dtype=object)
exp = final_df_dict['inf_expectation'].copy()
inf_1012 = [60.79, 0.45, 60.79, 0.45, 60.79, 0.45, 60.79, 0.45, 60.79]
inf_430 = [0.47, 26.85, 55.49, 64.18, 0.38, 0.47, 26.85, 55.49, 64.18]
rev_1012 = [x[1] - x[0] for x in zip(inf_1012, inf_1012[1:])]
rev_430 = [x[1] - x[0] for x in zip(inf_430, inf_430[1:])]
for n in range(2,10):
exp[f'{12 * n}-{12 * (n - 1)}'] = exp[f'task.{n * 12}.player.inf_expectation'] -\
exp[f'task.{(n - 1) * 12}.player.inf_expectation']
exp['revisions'] = np.nan
for i in range(len(exp)):
x = 0
for n in range(2,10):
if exp[f'{12 * n}-{12 * (n - 1)}'].iloc[i] != 0:
x += 1
else:
pass
exp['revisions'].iloc[i] = x
## Graph expimates
cols = [c for c in exp.columns.to_list() if ('task.' in c)]
fig, ax = plt.subplots(figsize=(24, 10))
## Actual inflation
## 10x12 pre
df = exp[cols][
(exp['participant.inflation'] == '1012') & (exp['participant.day'] < 3) & (
exp['revisions'] >= 0
)
].T
df_cols = ['_' + str(col) for col in df.columns]
df_cols[0] = '10x12 pre'
df.columns = df_cols
df.plot(ax=ax, color='r', alpha=0.1)
# ax.get_legend().remove()
## 10x12 post
df = exp[cols][
(exp['participant.inflation'] == '1012') & (exp['participant.day'] >= 3) & (
exp['revisions'] >= 0
)
].T
df_cols = ['_' + str(col) for col in df.columns]
df_cols[0] = '10x12 post'
df.columns = df_cols
df.plot(ax=ax, color='b', alpha=0.1)
# ax.get_legend().remove()
plt.axhline(y=60.79, color='g', linestyle=':', label='max inflation')
plt.axhline(y=0, color='black', linestyle='-')
plt.plot(inf_1012, color='#f2f542', linewidth=4, label='actual inflation')
plt.legend(loc = 'upper left')
plt.title('10x12 expectations')
fig, ax = plt.subplots(figsize=(24, 10))
## 4x30 pre
df = exp[cols][
(exp['participant.inflation'] == '430') & (exp['participant.day'] < 3) & (
exp['revisions'] >= 0
)
].T
df_cols = ['_' + str(col) for col in df.columns]
df_cols[0] = '4x30 pre'
df.columns = df_cols
df.plot(ax=ax, color='r', alpha=0.1)
# ax.get_legend().remove()
## 4x30 post
df = exp[cols][
(exp['participant.inflation'] == '430') & (exp['participant.day'] >= 3) & (
exp['revisions'] >= 0
)
].T
df_cols = ['_' + str(col) for col in df.columns]
df_cols[0] = '4x30 post'
df.columns = df_cols
df.plot(ax=ax, color='b', alpha=0.1)
# ax.get_legend().remove()
plt.axhline(y=64.18, color='g', linestyle=':', label='max inflation')
plt.axhline(y=0, color='black', linestyle='-')
plt.plot(inf_430, color='#f2f542', linewidth=4, label='actual inflation')
plt.legend(loc = 'upper left')
plt.title('4x30 expectations')
## Graph revisions
cols = [c for c in exp.columns.to_list() if ('-' in c)]
fig, ax = plt.subplots(figsize=(24, 10))
## 10x12 pre
df = exp[cols][
(exp['participant.inflation'] == '1012') & (exp['participant.day'] < 3) & (
exp['revisions'] >= 0
)
].T
df_cols = ['_' + str(col) for col in df.columns]
df_cols[0] = '10x12 pre'
df.columns = df_cols
df.plot(ax=ax, color='r', alpha=0.1)
# ax.get_legend().remove()
## 10x12 post
df = exp[cols][
(exp['participant.inflation'] == '1012') & (exp['participant.day'] >= 3) & (
exp['revisions'] >= 0
)
].T
df_cols = ['_' + str(col) for col in df.columns]
df_cols[0] = '10x12 post'
df.columns = df_cols
df.plot(ax=ax, color='b', alpha=0.1)
# ax.get_legend().remove()
plt.axhline(y=60.79, color='g', linestyle=':', label='max inflation')
plt.axhline(y=0, color='black', linestyle='-')
plt.plot(rev_1012, color='#f2f542', linewidth=4, label='actual inflation')
plt.legend(loc = 'upper left')
plt.title('10x12 revisions')
fig, ax = plt.subplots(figsize=(24, 10))
## 4x30 pre
df = exp[cols][
(exp['participant.inflation'] == '430') & (exp['participant.day'] < 3) & (
exp['revisions'] >= 0
)
].T
df_cols = ['_' + str(col) for col in df.columns]
df_cols[0] = '4x30 pre'
df.columns = df_cols
df.plot(ax=ax, color='r', alpha=0.1)
# ax.get_legend().remove()
## 4x30 post
df = exp[cols][
(exp['participant.inflation'] == '430') & (exp['participant.day'] >= 3) & (
exp['revisions'] >= 0
)
].T
df_cols = ['_' + str(col) for col in df.columns]
df_cols[0] = '4x30 post'
df.columns = df_cols
df.plot(ax=ax, color='b', alpha=0.1)
# ax.get_legend().remove()
plt.axhline(y=64.18, color='g', linestyle=':', label='max inflation')
plt.axhline(y=0, color='black', linestyle='-')
plt.plot(rev_430, color='#f2f542', linewidth=4, label='actual inflation')
plt.legend(loc = 'upper left')
plt.title('4x30 revisions')
Text(0.5, 1.0, '4x30 revisions')
cols = [c for c in exp.columns.to_list() if ('task.' in c)]
fig, ax = plt.subplots(figsize=(20,20))
df1 = exp[cols][(exp['participant.inflation'] == '430') & (
exp['participant.day'] < 3
)]
df1.hist(ax=ax, color='r', label='pre')
fig, ax = plt.subplots(figsize=(20,20))
# ax = fig.gca()
df2 = exp[cols][(exp['participant.inflation'] == '430') & (
exp['participant.day'] >= 3
)]
df2.hist(ax=ax, color='b', label='post')
# ax.legend(loc='upper right')
# plt.show()
fig, ax = plt.subplots(figsize=(20,20))
df1 = exp[cols][(exp['participant.inflation'] == '1012') & (
exp['participant.day'] < 3
)]
df1.hist(ax=ax, color='r', label='pre')
fig, ax = plt.subplots(figsize=(20,20))
# ax = fig.gca()
df2 = exp[cols][(exp['participant.inflation'] == '1012') & (
exp['participant.day'] >= 3
)]
df2.hist(ax=ax, color='b', label='post')
array([[<AxesSubplot:title={'center':'task.12.player.inf_expectation'}>,
<AxesSubplot:title={'center':'task.24.player.inf_expectation'}>,
<AxesSubplot:title={'center':'task.36.player.inf_expectation'}>],
[<AxesSubplot:title={'center':'task.48.player.inf_expectation'}>,
<AxesSubplot:title={'center':'task.60.player.inf_expectation'}>,
<AxesSubplot:title={'center':'task.72.player.inf_expectation'}>],
[<AxesSubplot:title={'center':'task.84.player.inf_expectation'}>,
<AxesSubplot:title={'center':'task.96.player.inf_expectation'}>,
<AxesSubplot:title={'center':'task.108.player.inf_expectation'}>]],
dtype=object)
plt.subplots()
est['revisions'][(est['participant.inflation'] == '1012') & (
est['participant.day'] < 3
)].hist(color='r', label='10x12 pre-intervention')
est['revisions'][(est['participant.inflation'] == '1012') & (
est['participant.day'] >= 3
)].hist(color='b', alpha = 0.4, label='10x12 post-intervention')
plt.legend(loc='upper left')
plt.subplots()
est['revisions'][(est['participant.inflation'] == '430') & (
est['participant.day'] < 3
)].hist(color='r', label='4x30 pre-intervention')
est['revisions'][(est['participant.inflation'] == '430') & (
est['participant.day'] >= 3
)].hist(color='b', alpha = 0.4, label='4x30 post-intervention')
plt.legend(loc='upper left')
<matplotlib.legend.Legend at 0x24229b8d910>
cols = [c for c in est.columns.to_list() if ('task.' not in c) and ('.day' not in c)]
est[cols].groupby(['participant.inflation', est['participant.day'] < 3]).mean()
| 24-12 | 36-24 | 48-36 | 60-48 | 72-60 | 84-72 | 96-84 | 108-96 | 120-108 | revisions | ||
|---|---|---|---|---|---|---|---|---|---|---|---|
| participant.inflation | participant.day | ||||||||||
| 1012 | False | 18.857143 | -12.704762 | 15.380952 | -12.895238 | 14.333333 | -12.323810 | 18.485714 | -13.714286 | 29.009524 | 8.371429 |
| True | 18.212389 | -10.185841 | 14.761062 | -9.398230 | 11.548673 | -12.309735 | 18.205357 | -13.232143 | 25.250000 | 8.391304 | |
| 430 | False | 0.219048 | 7.933333 | 8.361905 | 6.466667 | -14.704762 | 0.342857 | 6.009524 | 11.161905 | 16.600000 | 7.619048 |
| True | 1.598214 | 8.660714 | 6.464286 | 10.776786 | -14.035714 | -1.419643 | 6.455357 | 10.580357 | 18.125000 | 7.777778 |
plt.subplots()
exp['revisions'][(exp['participant.inflation'] == '1012') & (
exp['participant.day'] < 3
)].hist(color='r', label='10x12 pre-intervention')
exp['revisions'][(exp['participant.inflation'] == '1012') & (
exp['participant.day'] >= 3
)].hist(color='b', alpha = 0.4, label='10x12 post-intervention')
plt.legend(loc='upper left')
plt.subplots()
exp['revisions'][(exp['participant.inflation'] == '430') & (
exp['participant.day'] < 3
)].hist(color='r', label='4x30 pre-intervention')
exp['revisions'][(exp['participant.inflation'] == '430') & (
exp['participant.day'] >= 3
)].hist(color='b', alpha = 0.4, label='4x30 post-intervention')
plt.legend(loc='upper left')
<matplotlib.legend.Legend at 0x2422f4f1730>
cols = [c for c in exp.columns.to_list() if ('task.' not in c) and ('.day' not in c)]
exp[cols].groupby(['participant.inflation', exp['participant.day'] < 3]).describe().T
| participant.inflation | 1012 | 430 | |||
|---|---|---|---|---|---|
| participant.day | False | True | False | True | |
| 24-12 | count | 105.000000 | 113.000000 | 105.000000 | 112.000000 |
| mean | 4.914286 | 16.752212 | 2.095238 | -1.026786 | |
| std | 25.220228 | 22.193762 | 10.407582 | 15.098750 | |
| min | -105.000000 | -27.000000 | -24.000000 | -45.000000 | |
| 25% | -3.000000 | 2.000000 | 0.000000 | -4.250000 | |
| 50% | 3.000000 | 8.000000 | 1.000000 | 0.000000 | |
| 75% | 12.000000 | 26.000000 | 4.000000 | 2.000000 | |
| max | 89.000000 | 95.000000 | 57.000000 | 106.000000 | |
| 36-24 | count | 105.000000 | 113.000000 | 105.000000 | 112.000000 |
| mean | 4.961905 | -3.752212 | 2.990476 | 9.857143 | |
| std | 22.217857 | 21.998186 | 16.688605 | 15.200674 | |
| min | -59.000000 | -110.000000 | -66.000000 | -35.000000 | |
| 25% | -1.000000 | -11.000000 | -1.000000 | 0.750000 | |
| 50% | 1.000000 | 0.000000 | 2.000000 | 7.000000 | |
| 75% | 12.000000 | 6.000000 | 9.000000 | 17.000000 | |
| max | 106.000000 | 61.000000 | 66.000000 | 68.000000 | |
| 48-36 | count | 105.000000 | 113.000000 | 105.000000 | 112.000000 |
| mean | -1.542857 | 2.955752 | 2.247619 | 2.178571 | |
| std | 20.794336 | 16.102013 | 14.671913 | 15.858163 | |
| min | -66.000000 | -49.000000 | -43.000000 | -75.000000 | |
| 25% | -7.000000 | -3.000000 | -1.000000 | -4.250000 | |
| 50% | 1.000000 | 3.000000 | 1.000000 | 3.000000 | |
| 75% | 8.000000 | 12.000000 | 9.000000 | 12.000000 | |
| max | 74.000000 | 55.000000 | 57.000000 | 36.000000 | |
| 60-48 | count | 105.000000 | 113.000000 | 105.000000 | 112.000000 |
| mean | 4.019048 | 2.522124 | 5.028571 | 8.017857 | |
| std | 23.030490 | 22.377483 | 19.515505 | 20.558413 | |
| min | -69.000000 | -72.000000 | -71.000000 | -96.000000 | |
| 25% | -5.000000 | -8.000000 | -1.000000 | -1.250000 | |
| 50% | 0.000000 | 0.000000 | 3.000000 | 3.000000 | |
| 75% | 10.000000 | 8.000000 | 10.000000 | 17.250000 | |
| max | 71.000000 | 100.000000 | 82.000000 | 65.000000 | |
| 72-60 | count | 105.000000 | 113.000000 | 105.000000 | 112.000000 |
| mean | -1.904762 | -1.646018 | -4.152381 | -5.517857 | |
| std | 19.376097 | 21.904387 | 19.614938 | 20.719483 | |
| min | -66.000000 | -77.000000 | -93.000000 | -78.000000 | |
| 25% | -7.000000 | -7.000000 | -9.000000 | -15.000000 | |
| 50% | 1.000000 | 0.000000 | -2.000000 | -1.500000 | |
| 75% | 8.000000 | 5.000000 | 2.000000 | 4.500000 | |
| max | 57.000000 | 65.000000 | 62.000000 | 42.000000 | |
| 84-72 | count | 105.000000 | 113.000000 | 105.000000 | 112.000000 |
| mean | 5.666667 | 3.415929 | 1.980952 | -1.901786 | |
| std | 19.741925 | 21.775939 | 15.160666 | 16.515873 | |
| min | -29.000000 | -58.000000 | -50.000000 | -54.000000 | |
| 25% | -5.000000 | -4.000000 | -4.000000 | -8.000000 | |
| 50% | 0.000000 | 1.000000 | 0.000000 | 0.000000 | |
| 75% | 9.000000 | 10.000000 | 5.000000 | 5.000000 | |
| max | 66.000000 | 80.000000 | 58.000000 | 45.000000 | |
| 96-84 | count | 105.000000 | 112.000000 | 105.000000 | 112.000000 |
| mean | -3.476190 | -1.839286 | 0.314286 | 3.267857 | |
| std | 24.493365 | 26.953598 | 16.731657 | 17.780434 | |
| min | -67.000000 | -94.000000 | -84.000000 | -63.000000 | |
| 25% | -7.000000 | -13.250000 | -3.000000 | -2.000000 | |
| 50% | 0.000000 | 0.000000 | 1.000000 | 3.000000 | |
| 75% | 6.000000 | 8.250000 | 6.000000 | 12.000000 | |
| max | 99.000000 | 63.000000 | 45.000000 | 69.000000 | |
| 108-96 | count | 105.000000 | 112.000000 | 105.000000 | 112.000000 |
| mean | 8.419048 | 4.616071 | 8.380952 | 5.696429 | |
| std | 25.232298 | 24.659938 | 16.802233 | 26.788070 | |
| min | -95.000000 | -66.000000 | -28.000000 | -183.000000 | |
| 25% | -2.000000 | -5.000000 | -1.000000 | -1.250000 | |
| 50% | 3.000000 | 2.000000 | 5.000000 | 1.500000 | |
| 75% | 16.000000 | 11.000000 | 13.000000 | 14.250000 | |
| max | 70.000000 | 99.000000 | 85.000000 | 72.000000 | |
| revisions | count | 105.000000 | 115.000000 | 105.000000 | 117.000000 |
| mean | 7.171429 | 7.391304 | 6.942857 | 7.094017 | |
| std | 1.369005 | 1.226145 | 1.343278 | 1.383293 | |
| min | 0.000000 | 2.000000 | 0.000000 | 1.000000 | |
| 25% | 7.000000 | 7.000000 | 7.000000 | 7.000000 | |
| 50% | 8.000000 | 8.000000 | 7.000000 | 8.000000 | |
| 75% | 8.000000 | 8.000000 | 8.000000 | 8.000000 | |
| max | 8.000000 | 8.000000 | 8.000000 | 8.000000 | |
df = final_df_dict['decision'].copy()
cols = [c for c in df.columns.to_list() if 'task.' in c]
df[cols] = df[cols].astype(float)
fig, ax = plt.subplots(figsize=(30,30))
df1 = df[cols][(df['participant.inflation'] == '1012') & (
df['participant.day'] < 3)]
df1.hist(ax=ax, bins=20, color='r', label='pre')
plt.legend(loc='upper left')
fig, ax = plt.subplots(figsize=(30,30))
df1 = df[cols][(df['participant.inflation'] == '1012') & (
df['participant.day'] >= 3)]
df1.hist(ax=ax, bins=20, color='b', label='post')
plt.legend(loc='upper left')
fig, ax = plt.subplots(figsize=(30,30))
df1 = df[cols][(df['participant.inflation'] == '430') & (
df['participant.day'] < 3)]
df1.hist(ax=ax, bins=20, color='r', label='pre')
plt.legend(loc='upper left')
fig, ax = plt.subplots(figsize=(30,30))
df1 = df[cols][(df['participant.inflation'] == '430') & (
df['participant.day'] >= 3)]
df1.hist(ax=ax, bins=20, color='b', label='post')
plt.legend(loc='upper left')
No handles with labels found to put in legend. No handles with labels found to put in legend. No handles with labels found to put in legend. No handles with labels found to put in legend.
<matplotlib.legend.Legend at 0x2422e88cc40>